﻿CREATE PROCEDURE [dbo].[ArticleSales_CategoryMargins]
	@RangeReviewId int
AS
	SELECT c.Id, c.Name, SUM(s.GM) / SUM(s.Sales) as Margin
	FROM ArticleSales s
	inner join Articles a on a.Id = s.ArticleId
	inner join Categories c on c.Id = a.CategoryId
	WHERE a.RangeReviewId = @RangeReviewId
	GROUP BY c.Id, c.Name
RETURN 0